﻿var div_friendlist='';
var gPageIndex = 1;
var _Ma_PageSize = 35;
//分页对象
var _Ma_FriendPage = null;
function choosefriends()
{
$('text_to').disabled=true;
showProgressBar(true);
    div_friendlist = '';
     WebServices.User.Mail.GetMemberFriends(MemberNo,1,_Ma_PageSize,onChFr);
}
function error()
{
    $EndMessageBox$();
}
function error1()
{
$('text_to').value="";
    $EndMessageBox$();
}
function onChFr(result){
var _kint=600;
    if(result[1].RecordCount == 0){
        $('span_nofriend').style.display = '';
         div_friendlist='<div id="div_checkfriends">'+ML305+' <br/><br/><input type="button" value="'+UR089+'" class="button" onclick="javascript:top.location=\'/contacts/search.htm\'">&nbsp;&nbsp;<input type="button" value="'+C0056+'" class="buttong" onclick="error1()" />';
         _kint=350;
        }else
        {
        _Ma_FriendPage=result[1];
    div_friendlist = '<div id="div_checkfriends"><ul class="tag_common_right">';
    for(i = 0; i<result[0].length; i++)
    {
        div_friendlist +="<li><input type='checkbox' "+($('text_to').value.indexOf(result[0][i].MemberNo+"("+result[0][i].Nickname+"),")>-1?"checked":"")+" id='"+result[0][i].MemberNo+"'  value='"+result[0][i].MemberNo+"("+result[0][i].Nickname.replace(/\'/gi,"&#39")+"),"+"' onclick='_Ma_cheMemberno(this)' /> <a href='/"+result[0][i].MemberNo+".htm' target='_blank'>"+result[0][i].Nickname+"</a></li>";
    }
    div_friendlist += '</ul><div class="clear"></div></div><div class="clear"></div><div id="_SR_divPage" class="DisplayNone"></div><div class="margin5"><input type="button" value="'+C0045+'" class="button" onclick="selectedOK()" />&nbsp;&nbsp;<input type="button" value="'+C0056+'" class="buttong" onclick="error1()" /></div><div id="_sr_FriendsTemple" style="display:none"><ul class="tag_common_right"><li><input type="checkbox" id="$MemberNo$" $Checked$ onclick="_Ma_cheMemberno(this)" value="$value$"/> <a href="/$MemberNo$.htm" target="_blank">$NickName$</a></li></ul></div>';
    }
    $("$divIput$").style.display = "none";
    var title = ML202;
    var obj = {};
    $ShowMessageBox$(title,div_friendlist,obj,error1,_kint);
    RendPageNavigator(_Ma_FriendPage,"_SR_divPage","$sr_GetPageFriend");
    showProgressBar(false);
    $('text_to').disabled=false;
}
function _Ma_cheMemberno(friendno)
{
    if(friendno.checked)
    {
        $('text_to').value+=friendno.value;
    }else
    {
      $('text_to').value=$('text_to').value.replace(friendno.value,"");  
    }
}
//获取页面数据（页索引）
function $sr_GetPageFriend(pageIndex)
{
    showProgressBar(true);	
    $sr_InitDataFriend(pageIndex);
}
function $sr_InitDataFriend(pageIndex)
{
    WebServices.User.Mail.GetMemberFriends(MemberNo,pageIndex,_Ma_PageSize,onChFr1);
}
function onChFr1(result)
{
    $sr_RendFriendList(result[0],"div_checkfriends");
    RendPageNavigator(result[1],"_SR_divPage","$sr_GetPageFriend");   
    showProgressBar(false); 
}
function $sr_RendFriendList(list,divID)
{
     var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");         
        if($get("_sr_FriendsTemple")==null) return;        
        var item= $get("_sr_FriendsTemple").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        var listCount = list.length;
        for (var index = 0; index < listCount; index++) 
        {
            var obj = list[index];                     
            var tmp = item.replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname).replace(/\$Checked\$/gi,($('text_to').value.indexOf(obj.MemberNo+"("+obj.Nickname+"),")>-1?"checked":"")).replace(/\$value\$/gi,(obj.MemberNo+"("+obj.Nickname+"),"));         
            listBuilder.append(tmp);           
        }
        var sTemp = listBuilder.toString();domDiv.innerHTML = sTemp;                  
    }
}
function selectedOK()
{  
    error();
}

function sendOK(re)
{
showProgressBar(false);
     $('text_to').value = '';
    $('text_subject').value = '';
    $('MessagesBox').style.display = '';
    $('texta_body').value='';
if(re)
{

   
    $('MessageText').innerHTML=ML303;
     }else
     {
      $('MessageText').innerHTML=ML305;
     }
}

function sendMsg()
{ 
var valDesc = $("texta_body").value;
$("span_nomessage").style.display = "none";
$('Stext_subject').style.display = 'none';
    if(!$ValidButton$()||$('text_subject').value.replace(/\s+/gi,"").length<1||valDesc.length<1 || valDesc.length>10000 ){if($('text_subject').value.replace(/\s+/gi,"").length<1||$('text_subject').value.length<0){$('Stext_subject').style.display = '';} if(valDesc.length<3 || valDesc.length>10000)
    {$("span_nomessage").style.display = "";}return;}
    showProgressBar(true);
    //try{$("txtDesc1").value=FCKeditorAPI.GetInstance('txtDesc1').GetXHTML(true); valDesc=$("txtDesc1").value}catch(e){}    
//    if(valDesc.length<3 || valDesc.length>10000)
//    {
//       // FCKeditorAPI.GetInstance('txtDesc1').Focus();
//        $("span_nomessage").style.display = "";
//         showProgressBar(false);
//        return;
//       
//    }    
    var membernos = $('text_to').value.split(',');
    var mList = "";
    for(i = 0;i<membernos.length;i++)
    {
        if(membernos[i].length > 0)
        {
        if(membernos[i].indexOf('(')>-1)
         {
            mList +=membernos[i].substring(0,membernos[i].indexOf('('));
         }else
         {
           mList +=membernos[i];
         }
        }
    }
    WebServices.User.Mail.WriteLetter(mList,MemberNo,$('text_subject').value,$('texta_body').value,sendOK);
}